import { message } from "antd";

export const exportUtils = (data: any, fileName: string | string[] | null) => {
  console.log(data);

  const url = window.URL.createObjectURL(data);
  const link = document.createElement('a');
  link.href = url;
  link.setAttribute('download', `${fileName}.xlsx`);
  link.click();

}

export const blobToJson = (data: any, name: any) => {
  console.log(data);

  if (data?.type == 'application/json') {
    const reader: any = new FileReader();
    reader.readAsText(data, 'utf-8');
    reader.onload = function () {
      const result = JSON.parse(reader?.result)
      if (result.success == false) {
        message.destroy()
        message.error('没有可导出的数据')
      }
    }
  } else {
    exportUtils(data, name)
  }
}